package org.itzheng.utils.common;

import android.graphics.Color;

/**
 * Created by admin on 2017/7/30.
 * 参考：http://blog.csdn.net/u010593680/article/details/50987671
 */

public class ColorUtils {
    /**
     * 取两个颜色间的渐变区间 中的某一点的颜色
     *
     * @param startColor 如：Color.YELLOW 或者 Color.argb(0xff, 0xff, 0x00, 0x00)
     *                   或者 getResources().getColor(R.color.colorAccent);
     * @param endColor
     * @param radio      百分比
     * @return
     */
    public int getColorFrom(int startColor, int endColor, float radio) {
        int redStart = Color.red(startColor);
        int blueStart = Color.blue(startColor);
        int greenStart = Color.green(startColor);
        int redEnd = Color.red(endColor);
        int blueEnd = Color.blue(endColor);
        int greenEnd = Color.green(endColor);

        int red = (int) (redStart + ((redEnd - redStart) * radio + 0.5));
        int greed = (int) (greenStart + ((greenEnd - greenStart) * radio + 0.5));
        int blue = (int) (blueStart + ((blueEnd - blueStart) * radio + 0.5));
        return Color.argb(255, red, greed, blue);
    }
}
